package org.gaaidou.ptarmigan.springboot.core.serialize;

import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.JsonDeserializer;
import org.gaaidou.ptarmigan.springboot.core.common.DateUtil;
import org.springframework.util.StringUtils;

import java.io.IOException;
import java.util.Date;


public class DateConverter extends JsonDeserializer<Date> {
    @Override
    public Date deserialize(JsonParser p, DeserializationContext ctxt) throws IOException {
        if (StringUtils.hasText(p.getValueAsString())) {
            return DateUtil.parse(p.getValueAsString());
        }
        return null;
    }
}
